package org.henau;
import org.henau.EmergencyHandlerChain.EmergencyEvent;
import org.henau.EmergencyHandlerChain.EmergencyHandlerChain;
import org.henau.PathCommand.AdjustPathCommand;
import org.henau.PathCommand.Path;
import org.henau.PathCommand.PathPlanner;
import org.henau.PathCommand.RemoteControl;
import org.henau.TaskLogger.FileLogger;
import org.henau.TaskLogger.PathPlanningTask;
import org.henau.TaskLogger.Task;
import org.henau.TaskLogger.TaskLogger;

public class AgriculturalSystem {
    private EmergencyHandlerChain safetyChain;
    private RemoteControl pathControl;
    private Task taskScheduler;

    public AgriculturalSystem() {
        safetyChain = new EmergencyHandlerChain();
        pathControl = new RemoteControl();

        // 创建带日志的路径规划任务
        Task baseTask = new PathPlanningTask();
        taskScheduler = new TaskLogger(baseTask, new FileLogger());
    }

    public void handleEmergency(EmergencyEvent event) {
        safetyChain.processEvent(event);
    }

    public void adjustPath(Path newPath) {
        PathPlanner planner = new PathPlanner();
        pathControl.setCommand(new AdjustPathCommand(planner, newPath));
        pathControl.executeCommand();
    }

    public void executeTasks() {
        taskScheduler.execute();
    }
}